<html>
<head><meta charset="utf-8"><title>Fixing VecDeque for stricter Stacked Borrows · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html">Fixing VecDeque for stricter Stacked Borrows</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148801090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/148801090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#148801090">(Nov 29 2018 at 17:07)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> any opinion on <a href="https://github.com/rust-lang/rust/pull/56161" target="_blank" title="https://github.com/rust-lang/rust/pull/56161">https://github.com/rust-lang/rust/pull/56161</a> ?</p>



<a name="148895909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/148895909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#148895909">(Nov 30 2018 at 23:01)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> on which aspect of it exactly? on the final changes that wound up being needed?</p>



<a name="150675062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150675062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150675062">(Dec 01 2018 at 08:15)</a>:</h4>
<p>yeah, basically. does that seem like a reasonable change to request (and make the original code UB, long-term)? can we land this change?</p>



<a name="150855869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150855869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150855869">(Dec 04 2018 at 15:43)</a>:</h4>
<p>I am still curious if there's any footing in being able to declare an as/coercion chain in a single expr as "atomic" in the sense that only the start and end matter (which would fix this, yes?)</p>



<a name="150861656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861656">(Dec 04 2018 at 17:02)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankro</span> I feel like my personal favorite solution is "the point at which the reference becomes an object"</p>



<a name="150861670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861670">(Dec 04 2018 at 17:02)</a>:</h4>
<p>while it's still a value, it can be invalid</p>



<a name="150861676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861676">(Dec 04 2018 at 17:02)</a>:</h4>
<p>i have no idea what object means in this context</p>



<a name="150861684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861684">(Dec 04 2018 at 17:02)</a>:</h4>
<p>like, when it gets bound to a name</p>



<a name="150861696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861696">(Dec 04 2018 at 17:03)</a>:</h4>
<p>(although it should also apply in return context)</p>



<a name="150861807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861807">(Dec 04 2018 at 17:04)</a>:</h4>
<p>i.e., <code>let x = &amp;&lt;invalid-lvalue&gt;;</code> &lt;- not valid, <code>let x = &amp;&lt;invalid-lvalue&gt; as &amp;T as &amp;T as *const T;</code> &lt;- fine</p>



<a name="150861910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861910">(Dec 04 2018 at 17:06)</a>:</h4>
<p>Did y'all ever go forward with being able to pass things by-value where references are expected?</p>



<a name="150861915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150861915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150861915">(Dec 04 2018 at 17:06)</a>:</h4>
<p>(maybe causes problems with this kind of logic)</p>



<a name="150862034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150862034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150862034">(Dec 04 2018 at 17:08)</a>:</h4>
<p>Likely too risky wrt breaking code expecting some address stability, but passing by value would also "create an object" in this terminology</p>



<a name="150862154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/150862154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#150862154">(Dec 04 2018 at 17:10)</a>:</h4>
<p>er, phrased like that it's the wrong way around for what you're saying, but the other way around (when the source code passes a reference) is fine too</p>



<a name="151098808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151098808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151098808">(Dec 07 2018 at 09:27)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  why are the <code>as *[const,mut] T</code> required ?</p>



<a name="151099054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151099054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151099054">(Dec 07 2018 at 09:33)</a>:</h4>
<p>Shouldn't <code>NonZero(reference)</code> just work ?</p>



<a name="151101357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101357">(Dec 07 2018 at 10:19)</a>:</h4>
<blockquote>
<p>i.e., <code>let x = &amp;&lt;invalid-lvalue&gt;;</code> &lt;- not valid, <code>let x = &amp;&lt;invalid-lvalue&gt; as &amp;T as &amp;T as *const T;</code> &lt;- fine</p>
</blockquote>
<p>IMO that's way too non-compositional. We should be able to describe behavior as a sequence of steps in a simple language (on the level of MIR, but not quite MIR). Seen from that lense, what you are saying sounds a bit like <a href="https://github.com/rust-lang/rfcs/pull/2582" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2582">my Raw Reference RFC</a>, but with more cases being translated to "the raw ref operation"?<br>
Crucially, I think we want a syntactic condition here, not something semantic/operational like "bound to a name".</p>



<a name="151101368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101368">(Dec 07 2018 at 10:19)</a>:</h4>
<blockquote>
<p>Shouldn't <code>NonZero(reference)</code> just work ?</p>
</blockquote>
<p>hm. maybe? the code had casts in it from the start</p>



<a name="151101484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101484">(Dec 07 2018 at 10:21)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> yeah <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b978e10ce4a5dbe90c31982c05075d74" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b978e10ce4a5dbe90c31982c05075d74">it works</a> but it also desugars to first creating a raw ref and then casting that to <code>*const</code> :(</p>



<a name="151101720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101720">(Dec 07 2018 at 10:25)</a>:</h4>
<p>so what's the point of the <code>as _</code> ?</p>



<a name="151101736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101736">(Dec 07 2018 at 10:25)</a>:</h4>
<p>maybe the code was trying to properly cast to a <code>*const T</code> but failed</p>



<a name="151101995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing%20VecDeque%20for%20stricter%20Stacked%20Borrows/near/151101995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Fixing.20VecDeque.20for.20stricter.20Stacked.20Borrows.html#151101995">(Dec 07 2018 at 10:30)</a>:</h4>
<blockquote>
<p>so what's the point of the <code>as _</code> ?</p>
</blockquote>
<p>beats me</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>